home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
003
/
datefilt.arc
/
DATEFILT.C
next >
Wrap
C/C++ Source or Header
|
1987-02-05
|
2KB
|
90 lines
#define TRUE 1
#define FALSE 0
#include <stdio.h>
struct date { int day,month,year; };
main(argc,argv)
int argc;
char *argv[];
{
char buffer[80],size[15],temp1[30],temp2[30],date[20];
char *bufptr, *gets();
int status,type,do_it;
char sign;
struct date temp;
struct date comp;
if (argc != 3) { printf("Usage date1 op date\n op -> 1 - < 2 - = 3 - >"); exit(1); }
type = atoi(argv[1]);
if (type == 1) sign = '<';
if (type == 2) sign = '=';
if (type == 3) sign = '>';
sscanf(argv[2],"%d/%d/%d",&comp.month,&comp.day,&comp.year);
fprintf(stderr,"Request: Files %c %s\n",sign,argv[2]);
bufptr = gets(buffer);
while (bufptr != NULL) {
if (strlen(bufptr) == 55) {
strncpy(temp1,buffer+2,12);
strncpy(date,buffer+46,9);
get_date(date,&temp);
do_it = FALSE;
switch (type) {
case 1 : if (datecmp(&comp,&temp) < NULL)
do_it = TRUE;
break;
case 2 : if (datecmp(&comp,&temp) == NULL)
do_it = TRUE;
break;
case 3 : if (datecmp(&comp,&temp) > NULL)
do_it = TRUE;
break;
}
if (do_it) printf("%s\n",buffer);
} else printf("%s\n",buffer);
bufptr = gets(buffer);
}
}
int month_no(month)
char month[];
{
static char *chk_month[] = { "JAN","FEB","MAR","APR","MAY",
"JUN","JUL","AUG","SEP","OCT",
"NOV","DEC" };
int i;
for (i=0;i<3;i++) month[i] = toupper(month[i]);
for (i=0;i<12;i++)
if (strncmp(month,chk_month[i],3) == NULL)
return(i+1);
return(0);
}
int get_date(date,a)
char date[];
struct date *a;
{
a->month = month_no(date);
sscanf(date+4,"%d %d",&(a->day),&(a->year));
}
int datecmp(a,b)
struct date *a;
struct date *b;
{
if ((a->year == b->year) && (a->month == b->month) && (a->day == b->day))
return(0);
if ((a->year == b->year) && (a->month == b->month) && (a->day > b->day))
return(-1);
if ((a->year == b->year) && (a->month == b->month) && (a->day < b->day))
return(1);
if ((a->year == b->year) && (a->month > b->month))
return(-1);
if ((a->year == b->year) && (a->month < b->month))
return(1);
if (a->year < b->year) return(1);
if (a->year > b->year) return(-1);
}